package com.yw.atp.service;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.yw.atp.model.Consult;
import com.yw.atp.model.Reply;
import com.yw.atp.model.Staff;


@Repository
@Transactional
public class ConsultService{
	@PersistenceContext
    private EntityManager em;
	public List<Consult> getConsults(Consult consult){
		Query query = em.createQuery("select c FROM  Consult c where c.content like :Content and c.status !='1' order by c.id desc");
		query.setParameter("Content","%"+consult.getContent()+"%");
		return (List<Consult>)query.getResultList();
	}
	
	
	public List<Consult> getPollingConsults(Integer maxID,String ids,Staff staff){
		StringBuffer sb = new StringBuffer();
		sb.append("select c FROM Consult c where c.id >:maxID and c.id not in ("+ids+") and c.status !='1' order by c.id desc");		
		Query query = em.createQuery(sb.toString());
		query.setParameter("maxID",maxID);
		return (List<Consult>)query.getResultList();
	}
}
